#include <stdio.h>
#include <stdlib.h>

int main (int argc, char const* argv[])
{
    int n, cnt, i, j, map[101][101], a[101][101], x, y, flg, ans;

    scanf("%d", &n);
    cnt = 1;

    while (cnt <= n) {
        scanf("%d %d", &x, &y);
        for (i = 0; i < x; i++) {
            for (j = 0; j < y; j++) {
                scanf("%d", &map[i][j]);
                a[i][j] = 0;
            }
        }

        for (i = 0; i < x; i++) {
            flg = 1;
            for (j = 1; j < y; j++) {
                if (map[i][0] != map[i][j]) {
                    flg = 0;
                }
            }

            if (flg) {
                for (j = 0; j < y; j++) {
                    a[i][j] = 1;
                }
            }
        }

        for (j = 0; j < y; j++) {
            flg = 1;
            for (i = 1; i < x; i++) {
                if (map[0][j] != map[i][j]) {
                    flg = 0;
                }
            }

            if (flg) {
                for (i = 0; i < x; i++) {
                    a[i][j] = 1;
                }
            }
        }

        ans = 1;
        for (i = 0; i < x; i++) {
            for (j = 0; j < y; j++) {
                if (a[i][j] != 1) {
                    ans = 0; break;
                }
            }
        }

        printf("Case #%d: ", cnt);
        if (ans) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }

        cnt++;
    }

    return 0;
}
